package com.ruoyi.web.member.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.member.domain.Families;
import com.ruoyi.member.service.IFamiliesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/member/family")
public class FamiliesController extends BaseController
{
    @Autowired
    private IFamiliesService familiesService;

    /**
     * 查询家庭信息列表
     */
    @PreAuthorize("@ss.hasPermi('member:family:list')")
    @GetMapping("/list")
    public TableDataInfo list(Families families)
    {
        startPage();
        List<Families> list = familiesService.selectFamiliesList(families);
        return getDataTable(list);
    }

    /**
     * 导出家庭信息列表
     */
    @PreAuthorize("@ss.hasPermi('member:family:export')")
    @Log(title = "家庭信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Families families)
    {
        List<Families> list = familiesService.selectFamiliesList(families);
        ExcelUtil<Families> util = new ExcelUtil<Families>(Families.class);
        util.exportExcel(response, list, "家庭信息数据");
    }

    /**
     * 获取家庭信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:family:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(familiesService.selectFamiliesById(id));
    }

    /**
     * 新增家庭信息
     */
    @PreAuthorize("@ss.hasPermi('member:family:add')")
    @Log(title = "家庭信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Families families)
    {
        return toAjax(familiesService.insertFamilies(families));
    }

    /**
     * 修改家庭信息
     */
    @PreAuthorize("@ss.hasPermi('member:family:edit')")
    @Log(title = "家庭信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Families families)
    {
        return toAjax(familiesService.updateFamilies(families));
    }

    /**
     * 删除家庭信息
     */
    @PreAuthorize("@ss.hasPermi('member:family:remove')")
    @Log(title = "家庭信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familiesService.deleteFamiliesByIds(ids));
    }
}
